package cn.shengchao.examstar.me.course.application.query.impl;

import cn.shengchao.examstar.me.course.application.query.CourseWatchTimeQuery;
import cn.shengchao.examstar.me.infrastructure.dao.ProductCourseUserDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 课程观看时长查询实现
 * CQRS模式的查询实现，通过MyBatis查询用户的课程观看时长
 */
@Service
@Slf4j
public class CourseWatchTimeQueryImpl implements CourseWatchTimeQuery {

    @Autowired
    private ProductCourseUserDao productCourseUserDao;

    @Override
    public Long getTotalWatchLengthBySpecificationType(Long userId, Long specificationTypeId) {
        try {
            // 通过MyBatis DAO查询总观看时长
            Long result = productCourseUserDao.getTotalWatchLengthBySpecificationType(userId, specificationTypeId);
            return result != null ? result : 0L;
        } catch (Exception e) {
            log.error("获取课程观看时长失败: userId={}, specificationTypeId={}", userId, specificationTypeId, e);
            return 0L;
        }
    }
} 